<?php
class Begin extends Zend_Form
{
    public function init()
    {
    	$this->setAction("/tender/begin");
    	$this->setMethod("post");

    	$begin = new Zend_Session_Namespace('tender/begin');

    	$city = new Zend_Form_Element_Text('city',array('id' => 'city_id'));
        $city->setLabel('Отправление из города')
        	->addFilter('StringTrim')
        	->addFilter('StripTags')
        	->setRequired(false);
		$city->setValue( isset($begin->city) ? $begin->city : '');

        $city_id = new Zend_Form_Element_Text('city_id',array('id' => 'city_id_hidden','class' => 'hidden'));
        $city_id->addFilter('StringTrim')
        	->addFilter('StripTags')
        	->addValidator('Digits')
        	->setRequired(true);
		$city_id->setValue( isset($begin->city_id) ? $begin->city_id : '');

		$daterange = new Zend_Form_Element_Text('daterange', array('id' => 'daterange', 'autocomplete'=>'off'));
		$daterange->setLabel('Возможные даты')
        	->addFilter('StringTrim')
        	->addFilter('StripTags')
        	->addValidator('Date', 'mm-dd-YYYY - mm-dd-YYYY')
        	->setRequired(true);
        $daterange->setValue( isset($begin->daterange) ? $begin->daterange : '');

        $buget= new Zend_Form_Element_Radio('budget', array('id' => 'budget'));
        $buget->setLabel('Бюджет')
        	->addMultiOption(0,'Любой')
        	->addMultiOption(1,'Указать')
      		->setSeparator('')
      		->getDecorator('Label')->setOption('escape', false);
      	$buget->setValue( isset($begin->budget) ? $begin->budget : 0);

        $budget_range_start = new Zend_Form_Element_Hidden('budget_range_start', array('id' => 'budget-range-start', 'class'=>'hidden'));
		$budget_range_start ->addFilter('StringTrim')
        	->addFilter('StringTrim')
			->addFilter('StripTags')
        	->addValidator('Digits')
        	->setDecorators(array('ViewHelper',array('HtmlTag', array('tag' => 'dd', 'class' => 'hidden'))))
        	;
      	$budget_range_start->setValue( isset($begin->budget_range_start) ? $begin->budget_range_start : 0);

        $budget_range_stop = new Zend_Form_Element_Hidden('budget_range_stop', array('id' => 'budget-range-stop', 'class'=>'hidden'));
		$budget_range_start ->addFilter('StringTrim')
        	->addFilter('StringTrim')
			->addFilter('StripTags')
        	->addValidator('Digits')
        	->setDecorators(array('ViewHelper',array('HtmlTag', array('tag' => 'dd', 'class' => 'hidden'))))
        	;
      	$budget_range_stop->setValue( isset($begin->budget_range_stop) ? $begin->budget_range_stop : 0);

        $buget_type = new Zend_Form_Element_Radio('budget_type', array('id' => 'budget-type', 'class' => 'hidden'));
        $buget_type->setLabel('Тип бюджета')
        	->addMultiOption(0,'Общий')
        	->addMultiOption(1,'На одного')
      		->setSeparator('')
      		->getDecorator('Label')->setOption('escape', false);
      	$buget_type->setValue( isset($begin->budget_type) ? $begin->budget_type : 0);

        $adult = new Zend_Form_Element_Select('adult', array('id' => 'adult'));
		$adult->setLabel('Кол-во взрослых')
        	->addFilter('StringTrim')
        	->addFilter('StripTags')
        	->addValidator('Digits')
        	->setRequired(true);

        for($i = 0; $i < 10; $i++ ) {
        	$adult->addMultiOption($i, $i+1);
        }
      	$adult->setValue( isset($begin->adult) ? $begin->adult : 1);

        $children = new Zend_Form_Element_Select('children', array('id' => 'children'));
		$children->setLabel('Кол-во детей')
        	->addFilter('StringTrim')
        	->addFilter('StripTags')
        	->addValidator('Digits')
        	->setRequired(true);

        for($i = 0; $i <= 10; $i++ ) {
        	$children->addMultiOption($i, $i);
        }
        $children->setValue( isset($begin->children) ? $begin->children: 0);

        $days = new Zend_Form_Element_Radio('days', array('id' => 'days'));
        $days->setLabel('Количество дней')
        	->addMultiOption(0,'Любое')
        	->addMultiOption(1,'Указать')
      		->setSeparator('')
      		->getDecorator('Label')->setOption('escape', false);
      	$days->setValue( isset($begin->days) ? $begin->days: 0);

        $days_choosed = new Zend_Form_Element_Hidden('days_choosed', array('id' => 'days_choosed', 'class'=>'hidden'));
		$days_choosed->addFilter('StringTrim')
        	->addFilter('StripTags')
        	->addValidator('Digits')
        	->setDecorators(array('ViewHelper',array('HtmlTag', array('tag' => 'dd', 'class' => 'hidden'))))
        	;
        $days_choosed->setValue( isset($begin->days_choosed) ? $begin->days_choosed: 2);

        $sbmt = new Zend_Form_Element_Submit('continue');
        $sbmt->setLabel('Продолжить');

        $this->addElements( array($city, $city_id, $daterange, $buget,
        					$budget_range_start, $budget_range_stop, $buget_type,
        					$adult, $children, $days, $days_choosed, $sbmt) );

        foreach ( $this->getElements() as $name => $element ) {
        	$element->setDecorators(
        		array(
		        	'ViewHelper',
        			'Errors',
		        	array(array('data' => 'HtmlTag'), array('tag' => 'div')),
		        	array(array('label' => 'Label'), array('tag' => 'div', 'escape' => false)),
		        	array(array('row' => 'HtmlTag'), array('tag' => 'div', 'id' => $element->getId().'-element', 'class' => $element->class )),
	        	)
        	);
        }

		$sbmt->setDecorators(array('ViewHelper', array('data'=>'HtmlTag', 'tag'=>'div')));

        $this->setDecorators(array(
		    'FormElements',
		    array('HtmlTag', array('tag' => 'div', 'id' => 'tender-begin')),
		    'Form',
		));
    }
}